import { getConfigKey } from "@/api/system/config";
const constant = {
    state: {
        numberDigit: 3,
        unitWeightDigit:3,
        weightDigit:6
      },
    
      mutations: {
        SET_NUMBER_DIGIT: (state, numberDigit) => {
          state.numberDigit = numberDigit
        },
        SET_UNIT_WEIGHT_DIGIT: (state, unitWeightDigit) => {
          state.unitWeightDigit = unitWeightDigit
        },
        SET_WEIGHT_DIGIT: (state, weightDigit) => {
          state.weightDigit = weightDigit
        }
      },
    
      actions: {
        setNumberDigit({commit}) {
          return new Promise((resolve, reject) => {
            getConfigKey('Number_digit').then(res => {
                commit('SET_NUMBER_DIGIT', parseInt(res.msg))
            }).catch(error => {
                reject(error)
            })
          })
        },
        setUnitWeightDigit({commit}) {
          return new Promise((resolve, reject) => {
            getConfigKey('Unit_weight_digit').then(res => {
                commit('SET_UNIT_WEIGHT_DIGIT', parseInt(res.msg))
            }).catch(error => {
                reject(error)
            })
          })
        },
        setWeightDigit({commit}) {
          return new Promise((resolve, reject) => {
            getConfigKey('Weight_digit').then(res => {
                commit('SET_WEIGHT_DIGIT', parseInt(res.msg))
            }).catch(error => {
                reject(error)
            })
          })
        },
    }
}

export default constant 